﻿using SharpNoisePCL;
using SharpNoisePCL.Noise;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpNoiseConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            RunGeneration(new RandomNoise(), "C# Random Noise");
            RunGeneration(new ValueNoise(), "C# Value Noise");
            RunGeneration(new PerlinNoise(), "C# Perlin Noise");
            RunGeneration(new SimplexNoise(), "C# Simplex Noise");
            RunGeneration(new WorleyNoise(), "C# Worley Noise");

            Console.ReadKey();
        }

        public static void RunGeneration(INoiseGenerator generator, string typeGen)
        {
            string sb= string.Empty;

            sb += "<table>\n";
            sb += "<tr>\n";
            sb +="<td></td>\n";
            sb +="<td>300x200</td>\n";
            sb +="<td>1024x768</td>\n";
            sb +="<td>1600x900</td>\n";
            sb +="<td>1280x1080</td>\n";
            sb +="</tr>\n";

            double at1 =0, at2=0, at3=0, at4=0;

            for (int i = 0; i < 10; i++)
            {
                sb+="<tr>\n";
                var t1 = Generate(generator, 300, 200);
                var t2 = Generate(generator, 1024, 768);
                var t3 = Generate(generator, 1600, 900);
                var t4 = Generate(generator, 1280, 1080);

                at1 += t1;
                at2 += t2;
                at3 += t3;
                at4 += t4;

                sb += string.Format("<td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td>\n","Sample " + (i + 1), t1,t2,t3,t4) ;
            
                sb += "</tr>\n";
            }

            sb +="<tr>\n";
            sb +=string.Format("<td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td>\n", "Average", at1/10, at2/10, at3/10, at4/10);            
            sb +="</tr>\n";

            sb +="<table>\n";
            sb += "<p>" + typeGen +"</p>\n";

            Console.WriteLine(sb);
        }

        private static double Generate(INoiseGenerator generator, int p1, int p2)
        {
            DateTime start = DateTime.Now;
            for (int x = 0; x < p1; x++)
            {
                for (int y = 0; y < p2; y++)
                {
                    generator.Get2D(x, y);
                }
            }
            return DateTime.Now.Subtract(start).TotalMilliseconds;
        }


    }
}
